# 13. 反射计数
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const lines = [];
rl.on('line', (line) => {
lines.push(line);
});
rl.on('close', () => {
const [w,h,x,y,sx,sy,t] = lines[0].split(' ').map(Number);
const matrix = lines.slice(1, 1+h).map(line => line.split('').map(Number));
let count = matrix[y][x];
while(t-- > 0) {
x += sx;
y += sy;
if(x === 0 || x === w - 1) sx = -sx;
if(y === 0 || y === h - 1) sy = -sy;
count += matrix[y][x];
}
console.log(count);
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23